<?php

/*
 * Elaboraco Por: Ebrain Cedeno.
 */

class Utility{
    
    public static function getPathCss(){
        
        $url_value = explode("/",substr($_SERVER['REQUEST_URI'],1));
        
        if ($indice = array_search("index.php", $url_value)){
	  if ($indice > 0){
                $temp_url_value = $url_value;
                $url_value = array();
                foreach ($temp_url_value as $llave=>$parameter){
                        if ($llave >= $indice){ 
                                $url_value[]=$parameter;
                        }
                }
	  }

	}
	elseif ($indice = array_search("",$url_value)){
	  if ($indice > 0){
		$temp_url_value = $url_value;
		$url_value = array();
		foreach ($temp_url_value as $llave=>$parameter){
			if ($llave >= $indice){
				$url_value[]=$parameter;
			}
		}
	  }
	
	}
        
        if (count($url_value) == 1){
            if (!file_exists('../css')){
                return './css';
            }
            else{
                return '../css';
            }
        }
        elseif (count($url_value) >= 2){
            return '../../css';
        }
    }
    
    public static function getPathTemplete(){
        
        $url_value = explode("/",substr($_SERVER['REQUEST_URI'],1));
        
        if ($indice = array_search("index.php", $url_value)){
	  if ($indice > 0){
                $temp_url_value = $url_value;
                $url_value = array();
                foreach ($temp_url_value as $llave=>$parameter){
                        if ($llave >= $indice){ 
                                $url_value[]=$parameter;
                        }
                }
	  }

	}
	elseif ($indice = array_search("",$url_value)){
	  if ($indice > 0){
		$temp_url_value = $url_value;
		$url_value = array();
		foreach ($temp_url_value as $llave=>$parameter){
			if ($llave >= $indice){
				$url_value[]=$parameter;
			}
		}
	  }
	
	}
        
        
        if (count($url_value) == 1){
            if (!file_exists('../templete')){
                return './templete';
            }
            else{
                return '../templete';
            }
        }
        elseif (count($url_value) >= 2){
            return '../../templete';            
        }
        
    }
    
    public static function getPathJs(){
        
        $url_value = explode("/",substr($_SERVER['REQUEST_URI'],1));
        
        if ($indice = array_search("index.php", $url_value)){
	  if ($indice > 0){
                $temp_url_value = $url_value;
                $url_value = array();
                foreach ($temp_url_value as $llave=>$parameter){
                        if ($llave >= $indice){ 
                                $url_value[]=$parameter;
                        }
                }
	  }

	}
	elseif ($indice = array_search("",$url_value)){
	  if ($indice > 0){
		$temp_url_value = $url_value;
		$url_value = array();
		foreach ($temp_url_value as $llave=>$parameter){
			if ($llave >= $indice){
				$url_value[]=$parameter;
			}
		}
	  }
	
	}
        
        
        if (count($url_value) == 1){
            if (!file_exists('../js')){
                return './js';
            }
            else{
                return '../js';
            }
        }
        elseif (count($url_value) >= 2){
            return '../../js';            
        }
        
    }
    
    public static function createUrl($module,$param=array()){
        
        $parameter = "";
        
        if (is_array($param) and count($param) > 0){
            $parameter .= "?";
            foreach ($param as $key=>$value){
                $parameter .= $key."=".$value."&";
            }
            $parameter = substr($parameter, 0,-1);
        }
        
        $url = "/index.php/".$module.$parameter;
        return $url;
        
    }   
}

?>
